<template>
	<view>

		<view class="banner-wrapper">
			<image :src="banner" mode="aspectFill"></image>
		</view>

		<view class="course-wrapper">

			<view class="course-item" v-for="(item, index) in list" :key="index" @click="toDetail(item)">
				<view class="course-item_hd">
					<image class="course-image" :src="item.coverImg" mode="aspectFill"></image>
				</view>
				<view class="course-item_bd">
					<view class="course-title">{{ item.courseName }}</view>
					<view class="course-click">
						<view>{{ item.lookNum }}阅读</view>
						<view class="course-btn">免费看</view>
					</view>
				</view>
			</view>

			<u-loadmore color="#999" marginTop="32rpx" marginBottom="32rpx" :status="loadmoreStatus" />
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				// Banner
				banner: 'https://octopus-wxapp.oss-cn-hangzhou.aliyuncs.com/octopus/course_banner.png',
				// 课程列表
				list: [],
				listParams: {
					pageSize: 10,
					pageNum: 1,
				},
				loadmoreStatus: 'loadmore',
			};
		},

		onShow() {
			this.getList(true)
		},

		onReachBottom() {
			this.getList()
		},
		/**
		 * 分享微信好友
		 */
		onShareAppMessage() {
			return {
				title: '加入老谭餐饮情报局看海量餐饮大数据',
				imageUrl: 'https://octopus-wxapp.oss-cn-hangzhou.aliyuncs.com/octopus/yxiao.png',
				path: `/pages/start/index`
			}
		},
		/**
		 * 分享微信朋友圈
		 */
		// onShareTimeline() {
		// 	return {
		// 		title: '加入老谭餐饮情报局看海量餐饮大数据',
		// 	}
		// },

		methods: {

			// 获取课程列表
			getList(refresh = false) {
				let that = this
				if (refresh) {
					that.listParams.pageNum = 1
					that.list = []
					that.loadmoreStatus = 'loadmore'
				}
				if (that.loadmoreStatus == 'nomore') return
				that.loadmoreStatus = 'loading'
				that.$api.getCourseList(that.listParams).then(res => {
					that.list = that.list.concat(res.rows)
					if (res.rows.length == that.listParams.pageSize) {
						that.listParams.pageNum++
						that.loadmoreStatus = 'loadmore'
					} else {
						that.loadmoreStatus = 'nomore'
					}
				})
			},

			// 查看课程详情
			toDetail(data) {
				uni.navigateTo({
					url: `/pages/course/detail?courseId=${data.courseId}`
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #F0F0F0;
	}
</style>
<style lang="scss" scoped>
	.banner-wrapper {
		height: 320rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.course-wrapper {
		position: relative;
		padding: 32rpx;
		margin-top: -24rpx;
		z-index: 10;
		box-sizing: border-box;

		&::before {
			content: '';
			display: block;
			width: 100%;
			height: 280rpx;
			background: linear-gradient(180deg, #FEF5BC, transparent);
			border-radius: 32rpx 32rpx 0 0;
			border-top: 2rpx solid #fff;
			position: absolute;
			top: 0;
			left: 0;
			z-index: -1;
		}

		.course-item {
			background-color: #fff;
			border-radius: 24rpx;
			padding: 24rpx;
			display: flex;
			margin-bottom: 16rpx;

			&_hd {
				flex-shrink: 0;

				.course-image {
					width: 192rpx;
					height: 144rpx;
					border-radius: 24rpx;
				}
			}

			&_bd {
				flex: 1;
				margin-left: 24rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				overflow: hidden;

				.course-title {
					font-size: 28rpx;
					font-weight: bold;
					color: #333;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}

				.course-click {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 26rpx;
					color: #999;

					.course-btn {
						color: #333;
						font-weight: bold;
						padding: 0 24rpx;
						line-height: 56rpx;
						border-radius: 16rpx;
						background-color: #FFDA2D;
					}
				}
			}
		}
	}
</style>
